package com.jzo2o.foundations.controller.operation;


import com.jzo2o.api.foundations.dto.response.RegionSimpleResDTO;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ConfigRegionSetReqDTO;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ConfigRegionResDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IConfigRegionService;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 区域表 前端控制器
 * </p>
 *
 * @author itcast
 * @since 2023-07-03
 */
@Validated
@RestController("serveRegionController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeRegionController {
    @Resource
    private IServeService serveService;


    @GetMapping("/page")
    @ApiOperation("区域服务分页")
    public PageResult<ServeResDTO> pageServeRegion(ServePageQueryReqDTO servePageQueryReqDTO) {
       return serveService.pageServeRegion(servePageQueryReqDTO);
    }
    @DeleteMapping("/{id}")
    @ApiOperation("根据服务id删除区域服务")
    public void deleteServeRegionByServeId(@PathVariable("id") long id) {
       serveService.deleteServeRegionByServeId(id);
    }

//    @PutMapping("/{id}")
//    @ApiOperation("根据服务id下架区域服务")
//    public void updateSaleStatusByServeId(@PathVariable("id") long id) {
//        serveService.updateSaleStatusByServeId(id);
//    }


    @PutMapping("/onHot/{id}")
    @ApiOperation("设置服务为热门字段")
    public void setOnHotByServeId(@PathVariable("id") long id) {
        serveService.setOnHotByServeId(id);
    }

    @PutMapping("/offHot/{id}")
    @ApiOperation("设置服务为非热门字段")
    public void setOffHotByServeId(@PathVariable("id") long id) {
        serveService.setOffHotByServeId(id);
    }


//    @PutMapping("/{id}")
//    @ApiOperation("区域启动")
//    public void activeRegion(@PathVariable("id") long id) {
//        serveService.updateSaleStatusByServeId(id);
//    }

    @PostMapping("/batch")
    @ApiOperation("区域服务批量新增")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOS) {
        serveService.add(serveUpsertReqDTOS);
    }
    @PutMapping("/{id}")
    @ApiOperation("区域服务修改价格")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "价格", required = true, dataTypeClass = BigDecimal.class)
    })
    public void updateRegionPrice(@PathVariable("id") Long id, @RequestParam("price") BigDecimal price) {
        serveService.updateRegionPrice(id,price);
    }


    @PutMapping("/onSale/{id}")
    @ApiOperation("区域上架服务")
    public void onSale(@PathVariable("id") Long id) {
        serveService.onSale(id);
    }
//    @DeleteMapping("/{id}")
//    @ApiOperation("删除区域服务")
//    public void deleteServe(@PathVariable("id") Long id) {
//        serveService.deleteServe(id);
//    }

    @PutMapping("/offSale/{id}")
    @ApiOperation("区域下架服务")
    public void offSale(@PathVariable("id") Long id) {
        serveService.offSale(id);
    }




}
